package com.java.db;

import java.sql.*;
import javax.sql.*;
import javax.naming.*;

public class CommonConnect {

	public Connection getConnection_ds1() throws SQLException,NamingException,ClassNotFoundException{
		Context ctx=null;
        DataSource ds = null;

        try {
      	
          ctx = new InitialContext();
          Context env = (Context)ctx.lookup("java:comp/env");
          ds = (DataSource) env.lookup("jdbc/dataSource1");

          return ds.getConnection();

        }
        catch(NamingException se) {
          se.printStackTrace();
          throw se;
        }
        finally{
          try{ if(ctx != null) ctx.close();}catch(NamingException e){ throw new NamingException();}
        }		
	}
	
	public Connection getConnection_ds2() throws SQLException,NamingException,ClassNotFoundException{
		Context ctx=null;
        DataSource ds = null;

        try {
      	
          ctx = new InitialContext();
          Context env = (Context)ctx.lookup("java:comp/env");
          ds = (DataSource) env.lookup("jdbc/dataSource2");

          return ds.getConnection();

        }
        catch(NamingException se) {
          se.printStackTrace();
          throw se;
        }
        finally{
          try{ if(ctx != null) ctx.close();}catch(NamingException e){ throw new NamingException();}
        }		
	}


}
